const currentTask = {
    namespaced: true,
    state: () => ({
        Task: {
            data: {},
            value: {}
        },
    }),
    mutations: {
        setCurrentTask(state, value) {
            state.Task = value
        },
        removeCurrentTask(state) {
            state.Task = {
                data: {},
                value: {}
            }
        }
    },
    actions: {
        removeAsyncCurrentTask(context) {
            context.commit('removeCurrentTask');
            return Promise.resolve()
        },
        setAsyncCurrentTask(context, value) {
            context.commit('setCurrentTask', value)
            if (Object.keys(value.data).length === 0) {
                localStorage.removeItem("currentTask/setCurrentTask");
            }
            let list = value.data.treeData.list;

            let xy = list.filter((item) => {
                return item.latitude && item.dimensionality
            })
            let latitude, dimensionality;

            if (xy instanceof Array && xy.length) {
                latitude = xy[0].latitude;
                dimensionality = xy[0].dimensionality;
            }

            latitude = xy[0].latitude;
            dimensionality = xy[0].dimensionality;


            return Promise.resolve({
                taskId: value.data.id,
                taskArray: value.data,
                list: value.data.treeData.list,
                center: [latitude, dimensionality],
                status: "success"
            })
        }
    },
    getters: {
        currentFilterTask(state) {
            return state.Task.data
        }
    }
}

export default currentTask
